<?php

namespace App\EventHandler;

use App\Event\Event;
use App\Logic\Order\Form\SubmitOrderForm;
use App\Util\UserIdentityHelper;
use EasySwoole\EasySwoole\Logger;
use App\Model\Order\OrderLogModel;

class AfterOrderSubmitHandler extends HandlerBase{
    function handle(){
        // TODO: Implement handle() method.

        Event::getInstance()->set(Event::EVENT_AFTER_ORDER_SUBMITTED, function(...$args){
            Logger::getInstance()->info('处理订单提交事件');
            $orderId = $args[1];
            /** @var SubmitOrderForm $submitForm */
            $submitForm = $args[0];

            $username = UserIdentityHelper::getUsername()?:'SYSTEM';

            $data = [
                'order_id' => $orderId,
                'operator' => $username ?? 'SYSTEM',
                'content'  => '创建订单成功',
            ];
            $result = OrderLogModel::insertData($data);

        });
    }


}
